package com.qch.rocket.demo.consumer;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @Author qch
 * @Date 2021/6/9
 */
public class MyConsumer {
    public static void main(String[] args) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("consumer_grp_06_01");
        consumer.setNamesrvAddr("192.168.142.134:9876");
        consumer.start();
        PullResult result = consumer.pull(new MessageQueue("tp_demo_06",
                        "node5.qch.com",
                        5),
                "*",
                0l,
                10);
        System.out.println(result);
        for (MessageExt messageExt : result.getMsgFoundList()) {
            System.out.println(new String(messageExt.getBody()));
        }
        consumer.shutdown();

    }
}
